//等待60s
var wait = 60;
function time(o) {
	if (wait == 0) {
		o.removeAttribute("disabled");
		o.value = "免费获取验证码";
		wait = 60;
	} else {
		o.setAttribute("disabled", true);
		o.value = wait + "秒后可重新发送";
		wait--;
		setTimeout(function() {
			time(o)
		}, 1000)
	}
}

function get(obj) {
	if (valNull()) {
		obj.disabled = true;
		$.ajax({
			url : "valCodeServlet.html",
			type : "Post",
			data : "Tel=" + $("#userPhone").val() + "," + $("#userPwd").val(),
			success : function(msg) {
				obj.disabled = false;
				var userPhone = $("#userPhone").val();
				if (msg == "Has") {
					$("<label   class='error userPhone'>该用户已注册</label>").insertAfter("#userPhone");
					return;
				}
				if (msg == userPhone) {
					time(obj);
					return;
				} else {
					valNull();
					return;
				}

			}
		});
	}

}
// 验证手机号
function valfocusMobile() {
	$(".userPhone").remove();
}
function valMobileblur() {
	if ($("#userPhone").val().length < 5) {
		$("<label   class='error userPhone'>用户名长度不能小于5</label>").insertAfter("#userPhone");
	}
}
// 获取m
var userPwd = $("#userPwd").val();
// 验证密码由数字和26英文字母组成
function valfocus() {
	$(".userpwd").remove();
}
function valblur() {
	userPwd = $("#userPwd").val();
	var reg = new RegExp("^[A-Za-z0-9]+$");
	if (!reg.test(userPwd)) {
		$("<label   class='error userpwd'>密码由数字和26个英文字母组成</label>")
				.insertAfter("#userPwd");
	}
}

function valNull() {
	var phone = $("#userPhone").val();
	var userPwd = $("#userPwd").val();
	if (phone == "") {
		$(".userPhone").remove();
		$("<label   class='error userPhone'>手机号不能为空！</label>").insertAfter(
				"#userPhone");
		return false;
	}
	if (userPwd == "") {
		$(".userpwd").remove();
		$("<label   class='error userpwd'>密码不能为空！</label>").insertAfter(
				"#userPwd");
		return false;
	}
	return true;
}
